package com.jiang.util;

import org.apache.commons.dbcp2.BasicDataSource;

import java.sql.Connection;
import java.sql.SQLException;

public class JdbcUtilDateSource {
    private static BasicDataSource bds;
    static{
        System.out.println ("创建连接池" );
        bds = new BasicDataSource( );
        bds.setInitialSize(5);
        bds.setUrl ("jdbc:mysql://master:3306/haha");
        bds.setDriverClassName ("com.mysql.cj.jdbc.Driver");
        bds.setUsername ("root");
        bds.setPassword ("123456");

    }
    public static Connection getCoon(){
        System.out.println ("获取链接" );
        try {
            return bds.getConnection ( );
        } catch (SQLException e) {
            e.printStackTrace ( );
        }
        return null;
    }
}
